package com.gxgeek.springfeaturesstudy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.*;
import org.springframework.context.ApplicationListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@Slf4j
public class SpringFeaturesStudyApplication {

	public static void main(String[] args) {
		SpringApplication application = new SpringApplication(SpringFeaturesStudyApplication.class);
		application.addListeners(new ApplicationListenerEnvironmentPrepared());
		application.addListeners(new ApplicationListenerFailed());
		application.addListeners(new ApplicationListenerPrepared());
		application.addListeners(new ApplicationListenerStarted());
		application.addListeners(new ApplicationListenerStarting());
		application.run(args);

//		SpringApplication.run(SpringFeaturesStudyApplication.class, args)
//		.addApplicationListener(new ApplicationListenerStarted());
	}

	@GetMapping("/hello")
	public String hello(){
		return "hello";
	}

	public static class ApplicationListenerEnvironmentPrepared implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
		@Override
		public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
			log.info("ApplicationListenerEnvironmentPrepared 事件");
		}
	}
	public static class ApplicationListenerFailed implements ApplicationListener<ApplicationFailedEvent> {
		@Override
		public void onApplicationEvent(ApplicationFailedEvent event) {
			log.info("ApplicationListenerFailed 事件");
		}

	}
	public static class ApplicationListenerPrepared implements ApplicationListener<ApplicationPreparedEvent> {
		@Override
		public void onApplicationEvent(ApplicationPreparedEvent event) {
			log.info("ApplicationPreparedEvent 事件");
		}

	}
	public static class ApplicationListenerStarting implements ApplicationListener<ApplicationStartingEvent> {
		@Override
		public void onApplicationEvent(ApplicationStartingEvent event) {
			log.info("ApplicationStartingEvent 事件");
		}

	}

	public static class ApplicationListenerStarted implements ApplicationListener<ApplicationStartedEvent> {
		@Override
		public void onApplicationEvent(ApplicationStartedEvent event) {
			log.info("ApplicationStartedEvent 事件");
		}

	}

}
